<template>
<div>
	<yd-cell-group>
        <yd-cell-item>
            <span slot="left">订单名称：</span>
            <input slot="right" type="text" placeholder="请输入订单名称"
            v-model="title" >
        </yd-cell-item>
        <yd-cell-item>
            <span slot="left">下单电话：</span>
            <input slot="right" type="number" placeholder="请输入电话"
            v-model="mobile" >
        </yd-cell-item>
        <yd-cell-item>
            <span slot="left">下单姓名：</span>
            <input slot="right" type="text" placeholder="请输入姓名"
            v-model="name" >
        </yd-cell-item>
        <yd-cell-item arrow>
            <span slot="left">起始时间：</span>
            <yd-datetime type="date" v-model="start_time" slot="right"></yd-datetime>
        </yd-cell-item>
        <yd-cell-item arrow>
            <span slot="left">结束时间：</span>
            <yd-datetime type="date" v-model="end_time" slot="right"></yd-datetime>
        </yd-cell-item>
    </yd-cell-group>

    <yd-button-group>
        <yd-button @click.native="search" size="large" type="primary" >查询</yd-button>
    </yd-button-group>
</div>
</template>

<script>

import { mapGetters } from 'vuex';
import { date2str, dateDiff } from '../../util/util'

export default {
	name: 'test',
	
	data () {
		return {
			title : '',
			mobile : '',
			name : '',
		  	start_time : date2str(new Date()),
		  	end_time : date2str(new Date()),
		}
	},

	components: {

		
	},

	computed : {
		...mapGetters([
			'company_code', 
			'userdata',
		]),
	},

	methods : {
		search () {
			const day = dateDiff(this.start_time, this.end_time);

			if(day < 0){
				this.$dialog.toast({
                    mes: '结束时间不能早于起始时间',
                    timeout: 1500,
                    icon: 'error',
                });
                return;
			}

			if(day > 30){
				this.$dialog.toast({
                    mes: '时间跨度不能超过30天',
                    timeout: 1500,
                    icon: 'error',
                });
                return;
			}

			console.log(day);

			let para = {
				'company_code' : this.company_code,
				'start_time' : this.start_time,
				'end_time' : this.end_time,
			};

			if(this.title != ''){
				para['title'] = this.title;
			}

			if(this.mobile != ''){
				para['mobile'] = this.mobile;
			}

			if(this.name != ''){
				para['name'] = this.name;
			}


			this.$router.push({ 
				'name': 'fxorderlist', 
				'query' : para,
			});
		}
	},

	watch:{
	    
	},

	mounted () {
		
		
	},

}
</script>

<style scoped>

</style>
